package view.frontend.order;

import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JPanel;
import view.generaldesign.DesignLayout;

/**
 *
 * @author Sonny Sandberg
 */
public class NewOrderButtonPanel 
{
    private JPanel newOrderButtonPanel;
    private OrderContainer orderContainer;

    public NewOrderButtonPanel(OrderContainer view)
    {
        orderContainer = view;
        
        newOrderButtonPanel = new JPanel();
        newOrderButtonPanel.setBounds(-1, 83, 302, 40);
        newOrderButtonPanel.setOpaque(false);
        
        Dimension btnSize = new Dimension(90, 30);
        
        JButton btnStone = new JButton("gravsten");
        btnStone.setPreferredSize(btnSize);
        btnStone.setBorder(DesignLayout.T_FIELD_RED);
        btnStone.setFont(DesignLayout.STANDARD.deriveFont(12f));
        btnStone.setBackground(DesignLayout.T_FIELD_BG_COLOR);
        btnStone.addActionListener(new ActionListener() 
        {
            @Override
            public void actionPerformed(ActionEvent e)
            {
                beginOrder(true);
            }
        });
        
        JButton btnService = new JButton("service");
        btnService.setPreferredSize(btnSize);
        btnService.setBorder(DesignLayout.T_FIELD_RED);
        btnService.setFont(DesignLayout.STANDARD.deriveFont(12f));
        btnService.setBackground(DesignLayout.T_FIELD_BG_COLOR);
        btnService.addActionListener(new ActionListener() 
        {
            @Override
            public void actionPerformed(ActionEvent e)
            {
                beginOrder(false);
            }
        });
        
        newOrderButtonPanel.add(btnStone);
        newOrderButtonPanel.add(btnService);
        newOrderButtonPanel.setVisible(false);
    }
    
    private void beginOrder(boolean tombstoneOrNor)
    {
        orderContainer.getOrderSearch().getPanel().setVisible(false);
        orderContainer.getOrderSearchList().getPanel().setVisible(false);
        orderContainer.getNewOrderButtonPanel().getPanel().setVisible(false);
        orderContainer.getOrder().getPanel().setVisible(true);
        orderContainer.getOrder().resetOrder(tombstoneOrNor);
    }

    public JPanel getPanel()
    {
        return newOrderButtonPanel;
    }
}